package com.atguigu.service.impl;

import com.atguigu.entity.PlatformPropertyKey;
import com.atguigu.entity.PlatformPropertyValue;
import com.atguigu.mapper.PlatformPropertyKeyMapper;
import com.atguigu.service.PlatformPropertyKeyService;
import com.atguigu.service.PlatformPropertyValueService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 * 属性表 服务实现类
 * </p>
 *
 * @author zhangqiang
 * @since 2023-01-11
 */
@Service
public class PlatformPropertyKeyServiceImpl extends ServiceImpl<PlatformPropertyKeyMapper, PlatformPropertyKey> implements PlatformPropertyKeyService {
    @Autowired
    private PlatformPropertyValueService propertyValueService;

    //@Override
    public List<PlatformPropertyKey> getPropertyByCategoryId2(Long category1Id, Long category2Id, Long category3Id) {
        //1.根据商品分类id查询商品平台属性名称
        List<PlatformPropertyKey> propertyKeyList= baseMapper.getPropertyKeyByCategoryId(category1Id, category2Id, category3Id);
        //2.根据平台属性id查询平台属性值集合
        if(!CollectionUtils.isEmpty(propertyKeyList)){
            for (PlatformPropertyKey propertyKey : propertyKeyList) {
                QueryWrapper<PlatformPropertyValue> wrapper = new QueryWrapper<>();
                wrapper.eq("property_key_id",propertyKey.getId());
                List<PlatformPropertyValue> propertyValueList = propertyValueService.list(wrapper);
                propertyKey.setPropertyValueList(propertyValueList);
            }
        }
        return propertyKeyList;
    }
    //对查询平台属性进行优化
    @Override
    public List<PlatformPropertyKey> getPropertyByCategoryId(Long category1Id, Long category2Id, Long category3Id) {
        return baseMapper.getPropertyByCategoryId(category1Id, category2Id, category3Id);
    }
}
